<?php
namespace App\Model\Examples;

use PhalApi\Model\NotORMModel as NotORM;

/**

CREATE TABLE `phalapi_curd` (
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `title` varchar(20) DEFAULT NULL,
    `content` text,
    `state` tinyint(4) DEFAULT NULL,
    `post_date` datetime DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

 */

class City extends NotORM {

    protected function getTableName($id) {
        return 'city_view';
    }

    public function getListItems($page, $perpage) {
        return $this->getORM()
            ->select('*')
            ->order('pingname')
            ->limit(($page - 1) * $perpage, $perpage);
    }
    public function getHotCitys() {
        $total = $this->getORM()
            ->where('is_hot', '1');

        return $total;
    }
    public function getAllCitysByWord($word) {
        $total = $this->getORM();
        if(!empty($word)){
             $total=$total->where('cityname LIKE ?','%'.$word.'%');    
        }
        return $total;
    }
    //获得当前拼音下的城市列表
    public function getCitysByPingName($word) {
        $total = $this->getORM()
            ->select('id,cityid,cityname')
            ->where('pingname',$word);
        return $total;
    }

    public function getListTotal() {
        $total = $this->getORM()
            ->count('id');

        return intval($total);
    }
}
